<template>
  <el-drawer title="详情" :visible="visible" direction="rtl" :wrapperClosable="false"
             :close-on-press-escape="false" :show-close="true" @close="$emit('close')">
    <el-row v-if="rowData">
      <el-col :span="24" v-for="key in formDescKeys" :key="key">
        {{formDesc[key].label}}：{{rowData[key]}}
      </el-col>
    </el-row>
  </el-drawer>

</template>

<script>
import mixins from "../lib/mixins";
import request from "../../../../utils/request";

export default {
  name: "detailFormDrawer",
  mixins: [mixins],
  props: {
    visible: Boolean,
    rowData: Object,
    formDesc: Object,
  },
  computed:{
    formDescKeys(){
      if (!this.formDesc) return []
      return Object.keys(this.formDesc).filter(key=>{
        if (!this.formDesc[key].notDetail) return true
        else return false
      })
    }
  },
  data() {
    return {
      formData: {}
    }
  },
  methods: {
    resetForm() {
      this.getEleForm().resetForm();
    },
    addSave() {
      this.getEleForm().handleSubmitForm();
    },
    //
    requestFn(data) {
      // 伪代码
      return new Promise(async (resolve, reject) => {
        try {
          if (this.addUrl) {
            request({
              url: this.addUrl,
              method: 'post',
              data
            })
                .then(data => {
                  resolve()
                })
                .catch(error => {
                  reject(error)
                })
          } else {
            throw new Error("保存地址add_url未配置")
          }
        } catch (error) {
          this.$message.error(error.message)
        }
      })
    },
    // 成功后的进一步处理
    handleRequestSuccess() {
      this.$message.success('保存成功')
      this.$emit('saveSuccess')
    },
    // 失败后的进一步处理（内部已经有提示）
    handleRequestError() {

    },
  },
  watch: {
    visible(val) {
      if (val) {
        //初始化
      }
    }
  }
}
</script>

<style scoped>

</style>